/*
 * Copyright (c) 1993-1997, Silicon Graphics, Inc.
 * ALL RIGHTS RESERVED
 * Permission to use, copy, modify, and distribute this software for
 * any purpose and without fee is hereby granted, provided that the above
 * copyright notice appear in all copies and that both the copyright notice
 * and this permission notice appear in supporting documentation, and that
 * the name of Silicon Graphics, Inc. not be used in advertising
 * or publicity pertaining to distribution of the software without specific,
 * written prior permission.
 *
 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
 * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
 * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * US Government Users Restricted Rights
 * Use, duplication, or disclosure by the Government is subject to
 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
 * clause at DFARS 252.227-7013 and/or in similar or successor
 * clauses in the FAR or the DOD or NASA FAR Supplement.
 * Unpublished-- rights reserved under the copyright laws of the
 * United States.  Contractor/manufacturer is Silicon Graphics,
 * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
 *
 * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
 */
package cglesson.lesson01;

import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;

import cglesson.CGExample;

/**
 *  This program demonstrates geometric primitives and
 *  their attributes.
 *  Ported By
 *  @author <a href="mailto:eriq.adams@gmail.com">Eriq Muhammad Adams J.</a>
 */
public class Lines extends CGExample {

	@Override
	public void init() {
		GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		GL11.glShadeModel(GL11.GL_FLAT);
		GL11.glViewport(0, 0, width, height);
		GL11.glMatrixMode(GL11.GL_PROJECTION);
		GL11.glLoadIdentity();
		GLU.gluOrtho2D(0.0f, (float) width, 0.0f, (float) height);
	}

	@Override
	public void update(int delta) {

	}

	@Override
	public void render() {
		int i;

		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

		/* select white for all lines */
		GL11.glColor3f(1.0f, 1.0f, 1.0f);

		/* in 1st row, 3 lines, each with a different stipple */
		GL11.glEnable(GL11.GL_LINE_STIPPLE);

		GL11.glLineStipple(1, (short) 0x0101); /* dotted */
		drawOneLine(50.0f, 125.0f, 150.0f, 125.0f);
		GL11.glLineStipple(1, (short) 0x00FF); /* dashed */
		drawOneLine(150.0f, 125.0f, 250.0f, 125.0f);
		GL11.glLineStipple(1, (short) 0x1C47); /* dash/dot/dash */
		drawOneLine(250.0f, 125.0f, 350.0f, 125.0f);

		/* in 2nd row, 3 wide lines, each with different stipple */
		GL11.glLineWidth(5.0f);
		GL11.glLineStipple(1, (short) 0x0101); /* dotted */
		drawOneLine(50.0f, 100.0f, 150.0f, 100.0f);
		GL11.glLineStipple(1, (short) 0x00FF); /* dashed */
		drawOneLine(150.0f, 100.0f, 250.0f, 100.0f);
		GL11.glLineStipple(1, (short) 0x1C47); /* dash/dot/dash */
		drawOneLine(250.0f, 100.0f, 350.0f, 100.0f);
		GL11.glLineWidth(1.0f);

		/* in 3rd row, 6 lines, with dash/dot/dash stipple */
		/* as part of a single connected line strip */
		GL11.glLineStipple(1, (short) 0x1C47); /* dash/dot/dash */
		GL11.glBegin(GL11.GL_LINE_STRIP);
		for (i = 0; i < 7; i++)
			GL11.glVertex2f(50.0f + ((float) i * 50.0f), 75.0f);
		GL11.glEnd();

		/* in 4th row, 6 independent lines with same stipple */
		for (i = 0; i < 6; i++) {
			drawOneLine(50.0f + ((float) i * 50.0f), 50.0f,
					50.0f + ((float) (i + 1) * 50.0f), 50.0f);
		}

		/* in 5th row, 1 line, with dash/dot/dash stipple */
		/* and a stipple repeat factor of 5 */
		GL11.glLineStipple(5, (short) 0x1C47); /* dash/dot/dash */
		drawOneLine(50.0f, 25.0f, 350.0f, 25.0f);

		GL11.glDisable(GL11.GL_LINE_STIPPLE);
		GL11.glFlush();

	}

	private void drawOneLine(float x1, float y1, float x2, float y2) {
		GL11.glBegin(GL11.GL_LINES);
		GL11.glVertex2f((x1), (y1));
		GL11.glVertex2f((x2), (y2));
		GL11.glEnd();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Lines example = new Lines();
		example.start(400, 150, false, "Lines Example");

	}

}
